#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<bits/stdc++.h>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define PI pair<int,int>
#define PL pair<ll,ll>


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}


//#define INF 5340172838076674L
#define INF 1000000000
#define MOD (100000000-3)
struct node{
	int a,b;
	bool operator<(const node& x)const{
		return a>x.a;
	};
};

struct no3{
	int a,b,c;
	bool operator<(const no3& x)const{
		if(a!=x.a)return a>x.a;
		else return b>x.b;
	}
};

vector<int> edg[500005];
int vs[500005*2];
int dep[500005*2];
int id[500005];
int tr[500005*8];
int n,m,tot;

void dfs(int ind,int p,int &k,int d){
	dep[k]=d;
	vs[k++]=ind;
	for(auto i:edg[ind])if(i!=p){
		dfs(i,ind,k,d+1);
		dep[k]=d;
		vs[k++]=ind;
	}
}
void build(int ind,int a,int b){
	if(a==b){
		tr[ind]=a;
		return ;
	}
	int mid=(a+b)/2;
	build(lson(ind),a,mid);
	build(rson(ind),mid+1,b);
	tr[ind]=dep[tr[lson(ind)]]<dep[tr[rson(ind)]]?
		tr[lson(ind)]:tr[rson(ind)];
}
int que(int ind,int l,int r,int a,int b){
	if(a>=l&&b<=r){
		return tr[ind];
	}
	int mid=(a+b)/2;
	int x=-1,y=-1;
	if(mid>=l)x=que(lson(ind),l,r,a,mid);
	if(mid<r)y=que(rson(ind),l,r,mid+1,b);
	if(x==-1)return y;
	if(y==-1)return x;
	return dep[x]<dep[y]?x:y;
}
int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
	int s;
	n=read();m=read();s=read();
	int a,b;
	for(int i=1;i<n;i++){
		a=read();b=read();
		edg[a].push_back(b);
		edg[b].push_back(a);
	}
	tot=1;
	dfs(s,-1,tot,0);
	--tot;
	memset(id,-1,sizeof id);
	for(int i=1;i<=tot;i++){
		//cout<<vs[i]<<' ';
		if(id[vs[i]]==-1)id[vs[i]]=i;
	}
	build(1,1,tot);
	for(int i=0;i<m;i++){
		a=read();b=read();//cout<<a<<b<<' '<<id[a]<<' '<<id[b]<<endl;
		printf("%d\n",
			vs[que(1,min(id[a],id[b]),max(id[a],id[b]),1,tot)]);
	}
}